<?php
//开启session




  $id = !empty($_GET['id'])?$_GET['id']:'';

      
if(!empty($_POST)){


      //实现双击编辑功能
       if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

         $id = $_POST['id'];
         $val = $_POST['val'];
         $filed = $_POST['filed']; 

       
        // $_rows = edit('news',$id,$_POST);
          $sql = "update`news` set `$filed`='$val' where`id`=$id";
          //编写执行语句
          mysqli_query($link,$sql);
          //  // 获取影响的行数
          echo $_rows=mysqli_affected_rows($link);

          die;
       }
  


               
                 
  $_rows = edit('news',$id,$_POST); 

  if ($_rows>0) {
      echo '<script> alert ("新闻编辑成功");location.href="index.php?c=news&a=list&admin=1";</script>';die;
         
  }else{

      echo '<script> alert ("新闻编辑失败");history.go(-1);</script>';
          die;
  }


}



$data = getSelectByOne('news',"id=$id");

// select * from `news` where `id`=30
//  echo $sql="select * from `news` where `id`=$id";
// die;

// $result = mysqli_query($link,$sql);

// $data = mysqli_fetch_assoc($result);

// print_r($data);die;

//链接语句
include (VIEW_PATH.$admin.'layout.html');

?>

